<?php

namespace App\Listener;

use App\Amqp\Producer\FemalePushGiftProducer;
use App\Event\RegDoneEvent;
use App\Event\UserOnlineEvent;
use App\Helpers\Helper;
use App\Service\ServiceTrait\GetUserInfoTrait;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Amqp\Producer;

/**
 * @Listener
 */
class FemaleRegisterListener implements ListenerInterface
{
    use GetUserInfoTrait;

    public function listen(): array
    {
        return [
            //注册事件
            RegDoneEvent::class,
//            UserOnlineEvent::class
        ];
    }

    public function process(object $event)
    {
        $userInfo = $this->getUserInfo($event->userId);
        log_info(__CLASS__ . "=={$event->userId}");
        //男生不需要处理
        if ($userInfo->gender == 1){
            return;
        }

        //推送mq
        $message = new FemalePushGiftProducer(['user_id' => $event->userId]);
        $producer = ApplicationContext::getContainer()->get(Producer::class);
        $producer->produce($message);
    }
}